<?php
/**
 * Created by PhpStorm.
 * User: woody
 * Date: 17-2-16
 * Time: 下午10:46
 */

namespace App\Http\Controllers\Api;
use App\Models\Loanapplyapi;
use Illuminate\Http\Request;

class LoanapplyController extends ApiController {

    public function __construct()
    {
        parent::__construct();
        $this->_response['_active']['_model']       = 'loanapply';
        $this->_response['_active']['_action']      = '';
        $this->_response['_title']                  = '小一农货-贷款申请管理';
    }


    public function doAdd(\App\Http\Requests\Loanapply $request){
        $data = $request->all();
        global $g_uid;
        $id=$g_uid;

        $loanapplyModel = new Loanapplyapi();
        $loaninfo=Loanapplyapi::where('user_id', $id)->select('check_status')->first();

        if(empty($loaninfo)){
            $saveData = [
                'user_id'=>$id,
                'name' => $data['name'],
                'phone'=>$data['phone'],
                'money' => $data['money'],
                'weixin' => $data['weixin'],
                'ishavehouse' => $data['ishavehouse'],
                'apply_time' => date('Y-m-d H:i:s', time()),
                'check_status'=>'0',
            ];

            if($loanapplyModel->saveData($saveData)){
                return response()->json(['code' => 0, 'msg' => '提交成功']);
            }else{
                return response()->json(['code' => -1, 'msg' => '提交失败']);
            }
        }else if($loaninfo['check_status']==0){
            $loaninfo['check_status']='审核中';
            $this->_response['loanapply'] = $loaninfo;
            return response()->json(['code' => 1, 'msg' => $this->_response]);
        }else{
            $loaninfo['check_status']='审核完成';
            $this->_response['loanapply'] = $loaninfo;
            return response()->json(['code' => 2, 'msg' => $this->_response]);
        }



    }



}